<?php
App::uses('AppController', 'Controller');
/**
 * Distancias Controller
 *
 * @property Distancia $Distancia
 */
class DistanciasController extends AppController {


/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->Distancia->recursive = 0;
		$this->set('distancias', $this->paginate());
	}

/**
 * view method
 *
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		$this->Distancia->id = $id;
		if (!$this->Distancia->exists()) {
			throw new NotFoundException('Invalid distancia');
		}
		$this->set('distancia', $this->Distancia->read(null, $id));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Distancia->create();
			if ($this->Distancia->save($this->request->data)) {
				$this->Session->setFlash('The distancia has been saved');
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash('The distancia could not be saved. Please, try again.');
			}
		}
		$anuncios = $this->Distancia->Anuncio->find('list');
		$this->set(compact('anuncios'));
	}

/**
 * edit method
 *
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		$this->Distancia->id = $id;
		if (!$this->Distancia->exists()) {
			throw new NotFoundException(__('Invalid distancia'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Distancia->save($this->request->data)) {
				$this->Session->setFlash('The distancia has been saved');
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash('The distancia could not be saved. Please, try again.');
			}
		} else {
			$this->request->data = $this->Distancia->read(null, $id);
		}
		$anuncios = $this->Distancia->Anuncio->find('list');
		$this->set(compact('anuncios'));
	}

/**
 * delete method
 *
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->Distancia->id = $id;
		if (!$this->Distancia->exists()) {
			throw new NotFoundException('Invalid distancia');
		}
		if ($this->Distancia->delete()) {
			$this->Session->setFlash('Distancia deleted');
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash('Distancia was not deleted');
		$this->redirect(array('action' => 'index'));
	}
}
